package lab03;

import java.io.*;

public class Test08 {
    public static void main(String[] args) {
       try {
            FileReader fr1 = new FileReader("G://hello.txt");
            FileReader fr2 = new FileReader("G://hi.txt");
            BufferedReader br1 = new BufferedReader(fr1);
            BufferedReader br2 = new BufferedReader(fr2);
            BufferedWriter bw3 = new BufferedWriter(new FileWriter("G://good.txt"));

            String s,s1,s2;
            s = br1.readLine();
            s1 = br2.readLine();
            while(s!= null)
            {
                bw3.write(s);//写入第三个文件
                s = br1.readLine();
                bw3.newLine();//换行
            }
            while(s1!=null)
            {
                bw3.write(s1);
                s1 = br2.readLine();
                bw3.newLine();
            }
            br1.close();
            br2.close();
            bw3.close();
            System.out.println("文件合并成功");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
